package com.lawyers.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.lawyers.common.UserVO;
import com.lawyers.form.LogOffForm;


public class LogOffAction extends Action{
	
	private static Logger logger = Logger.getLogger(LoginAction.class);
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception
	{
		logger.info("Chau");
		LogOffForm lForm = (LogOffForm) form; 
		String forward = "display";
		if(request.getSession().getAttribute("USUARIO") != null){
			UserVO user = (UserVO) request.getSession().getAttribute("USUARIO");
			if(user.getUsername().equalsIgnoreCase(lForm.getUsername())){
				forward = "display";
				request.getSession().removeAttribute("USUARIO");
			}
		}
		return mapping.findForward(forward);
	}

}
